#include "include.h"

#define LPK_DI	0x29
#define SPK_DI	0x15

u8	dcsrst[] = {0x05,0x01,0x00};
//*************************************
// Sleep-Out
//*************************************
u8	Sleep_Out[] = {0x05,0x11,0x00};
u8	Sleep_IN[] = {0x05,0x10,0x00};
//DELAY	120
// Display-On
//*************************************
u8	Display_On[] = {0x05,0x29,0x00};

#define CMDNUM  (7)

		  
//*********************HX8394C  BOE8.0 800X1280 LCD INIT STAR*************************//
//************************************************************//
// Set EXTC
// Set EXTC
/*u8	dcs0[] = {0x29,0xB9,0xFF,0x83,0x94};
// Set Power
u8	dcs1[] = {0x29,0xB1,0x64,0x10,0x30,0x43,0x34,0x11,0xF1,0x81,0x70,0xD9,0x34,0x80,0xC0,0xD2,0x41};
// Set Display
u8	dcs2[] = {0x29,0xB2,0x45,0x64,0x0F,0x09,0x40,0x1C,0x08,0x08,0x1C,0x4D,0x00,0x00};
// Set CYC
u8	dcs3[] = {0x29,0xB4,0x07,0x6E,0x07,0x71,0x6F,0x70,0x00,0x00,0x01,0x6E,0x0F,0x6E,0x07,0x71,0x6F,0x70,0x00,0x00,0x01,0x6E,0x0F,0x6E};
// Set VCOM
u8	dcs4[] = {0x29,0xB6,0x6F,0x6F,};
// Set PANEL
u8	dcs5[] = {0x15,0xCC,0x09,};

// Set GIP_0
u8	dcs6[] = {0x29,0xD3,0x00,0x08,0x00,0x01,0x07,0x00,0x08,0x32,0x10,0x0A,0x00,0x05,0x00,0x20,0x0A,0x05,0x09,0x00,0x32,0x10,0x08,0x00,0x35,0x33,0x0D,0x07,0x47,0x0D,0x07,0x47,0x0F,0x08,};
// Set GIP_1
u8	dcs7[] = {0x29,0xD5,0x03,0x02,0x03,0x02,0x01,0x00,0x01,0x00,0x07,0x06,0x07,0x06,0x05,0x04,0x05,0x04,0x21,0x20,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x23,0x22,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,};
// Set GAMMA
u8	dcs8[] = {0x29,0xE0,0x03,0x17,0x1C,0x2D,0x30,0x3B,0x27,0x40,0x08,0x0B,0x0D,0x18,0x0F,0x12,0x15,0x13,0x14,0x07,0x12,0x14,0x17,0x03,0x17,0x1C,0x2D,0x30,0x3B,0x27,0x40,0x08,0x0B,0x0D,0x18,0x0F,0x12,0x15,0x13,0x14,0x07,0x12,0x14,0x17,};
// Sleep Out
u8	dcs9[] = {0x05,0x11,0x00,};
//delay_ms(250,
// Set BC Control
u8	dcs10[] = {0x29,0xC9,0x1F,0x2E,0x1E,0x1E,0x10,};
// Display On
u8	dcs11[] = {0x05,0x29,0x00,};
//delay_ms(10,	*/

u8	dcs0[] = {0x39,0xB9,0xFF,0x83,0x94};
// Set Power
//            1    2    3    4    5    6    7    8    9    10   11   12   13   14   15   16             
//u8 dcs1[] ={0x39,0xB1,0x64,0x10,0x30,0x43,0x34,0x11,0xF1,0x81,0x70,0xD9,0x34,0x80,0xC0,0xD2,0x41};
u8	dcs1[] = {0x39,0xB1,0x64,0x10,0x30,0x43,0x34,0x11,0xF1,0x81,0x70,0xD9,0x34,0x80,0xC0,0xD2,0x41};
// Set Display
u8	dcs2[] = {0x39,0xB2,0x45,0x64,0x0F,0x09,0x40,0x1C,0x08,0x08,0x1C,0x4D,0x00,0x00};
// Set CYC
u8	dcs3[] = {0x39,0xB4,0x07,0x6E,0x07,0x71,0x6F,0x70,0x00,0x00,0x01,0x6E,0x0F,0x6E,0x07,0x71,0x6F,0x70,0x00,0x00,0x01,0x6E,0x0F,0x6E};
// Set VCOM
u8	dcs4[] = {0x39,0xB6,0x6F,0x6F,};
// Set PANEL
u8	dcs5[] = {0x15,0xCC,0x09,}; // 09
//u8	dcs5[] = {0x39,0xCC,0x09,}; // 09

// Set GIP_0
u8	dcs6[] = {0x39,0xD3,0x00,0x08,0x00,0x01,0x07,0x00,0x08,0x32,0x10,0x0A,0x00,0x05,0x00,0x20,0x0A,0x05,0x09,0x00,0x32,0x10,0x08,0x00,0x35,0x33,0x0D,0x07,0x47,0x0D,0x07,0x47,0x0F,0x08,};
// Set GIP_1
u8	dcs7[] = {0x39,0xD5,0x03,0x02,0x03,0x02,0x01,0x00,0x01,0x00,0x07,0x06,0x07,0x06,0x05,0x04,0x05,0x04,0x21,0x20,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x23,0x22,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,};
// Set GAMMA
u8	dcs8[] = {0x39,0xE0,0x03,0x17,0x1C,0x2D,0x30,0x3B,0x27,0x40,0x08,0x0B,0x0D,0x18,0x0F,0x12,0x15,0x13,0x14,0x07,0x12,0x14,0x17,0x03,0x17,0x1C,0x2D,0x30,0x3B,0x27,0x40,0x08,0x0B,0x0D,0x18,0x0F,0x12,0x15,0x13,0x14,0x07,0x12,0x14,0x17,};
// Sleep Out
u8	dcs9[] = {0x05,0x11,0x00,};
//delay_ms(250,
// Set BC Control
u8	dcs10[] = {0x39,0xC9,0x1F,0x2E,0x1E,0x1E,0x10,};
// Display On
u8	dcs11[] = {0x05,0x29,0x00,};
//delay_ms(10,	
//u8	dcs12[] = {0x39,0xb0, 0x80, 0x01, 0x02, 0x0c};

void DcsPktWrite(u8 DCS_DI, u8 Len, u8* Ptr )
{
	u8 i=0;
	HDMI_WriteI2C_Byte( 0xff, 0xd4 );
	if( Len == 2 )
	{  	
		HDMI_WriteI2C_Byte( 0x01, 0x0c );
		HDMI_WriteI2C_Byte( 0x02, 0x04 );
		HDMI_WriteI2C_Byte( 0x03, DCS_DI );
		HDMI_WriteI2C_Byte( 0x03, *Ptr );
		HDMI_WriteI2C_Byte( 0x03, *( Ptr + 1 ) );
	}
	else
	{
		HDMI_WriteI2C_Byte( 0x01, 0x0E );
		HDMI_WriteI2C_Byte( 0x02, Len + 6 );
		HDMI_WriteI2C_Byte( 0x03, DCS_DI );
		HDMI_WriteI2C_Byte( 0x03, Len );
		HDMI_WriteI2C_Byte( 0x03, 0x00 );
		
		for( i = 0; i < Len; i++ )
		{
			HDMI_WriteI2C_Byte( 0x03, *Ptr );
			Ptr++;														   
		}
	}
	HAL_Delay(1);
	HDMI_WriteI2C_Byte( 0x01, 0x00 );
}


void LCD_Reset(void)
{
   
   /*//P10 = 0;
   HAL_GPIO_WritePin(RST_GPIO_Port, RST_Pin, GPIO_PIN_RESET);
   HAL_Delay(200);
   //P10 = 1;
   HAL_GPIO_WritePin(RST_GPIO_Port, RST_Pin, GPIO_PIN_RESET);
   HAL_Delay(200);*/
}

void InitPanel( void )
{
	//u8 dcslen=0,i=0;
	
	HDMI_WriteI2C_Byte(0xff,0x81);
	HDMI_WriteI2C_Byte(0x0e,0xef);
	HDMI_WriteI2C_Byte(0x0e,0xff);
	HDMI_WriteI2C_Byte(0x0b,0xfe);

	HDMI_WriteI2C_Byte(0xff,0x86);
	HDMI_WriteI2C_Byte(0x47,0x01);
	HDMI_WriteI2C_Byte(0x48,0x01);

	HDMI_WriteI2C_Byte(0xff,0xd4);
	HDMI_WriteI2C_Byte(0x20,0x2f);
	HDMI_WriteI2C_Byte(0x21,0x10);
	
	LCD_Reset();
	printf("\r\nStart initial panel");
	
	DcsPktWrite( dcs0[0], ( sizeof( dcs0 ) - 1 ), &dcs0[1] );
	DcsPktWrite( dcs1[0], ( sizeof( dcs1 ) - 1 ), &dcs1[1] );
	DcsPktWrite( dcs2[0], ( sizeof( dcs2 ) - 1 ), &dcs2[1] );
	DcsPktWrite( dcs3[0], ( sizeof( dcs3 ) - 1 ), &dcs3[1] );
	DcsPktWrite( dcs4[0], ( sizeof( dcs4 ) - 1 ), &dcs4[1] );
	DcsPktWrite( dcs5[0], ( sizeof( dcs5 ) - 1 ), &dcs5[1] );
	DcsPktWrite( dcs6[0], ( sizeof( dcs6 ) - 1 ), &dcs6[1] );
	DcsPktWrite( dcs7[0], ( sizeof( dcs7 ) - 1 ), &dcs7[1] );
	DcsPktWrite( dcs8[0], ( sizeof( dcs8 ) - 1 ), &dcs8[1] );
	DcsPktWrite( dcs9[0], ( sizeof( dcs9 ) - 1 ), &dcs9[1] );
	HAL_Delay(300);
	DcsPktWrite( dcs10[0], ( sizeof( dcs10 ) - 1 ), &dcs10[1] );
	DcsPktWrite( dcs11[0], ( sizeof( dcs11 ) - 1 ), &dcs11[1] );
	HAL_Delay(10);
	  //dcs12
	//DcsPktWrite( dcs12[0], ( sizeof( dcs12 ) - 1 ), &dcs12[1] );
} 

